abstract class Op {
    char ch;

    public Op() {
        ch = ' ';
    }

    public Op(char ch) {
        this.ch = ch;
    }

    abstract public int calc(int a, int b);
}

class Add extends Op {
    public Add() {
        super('+');
    }

    public int calc(int a, int b) {
        return a + b;
    }
}

class Sub extends Op {
    public Sub() {
        super('-');
    }

    public int calc(int a, int b) {
        return a - b;
    }
}

class Mul extends Op {
    public Mul() {
        super('*');
    }

    public int calc(int a, int b) {
        return a * b;
    }
}
class Div extends Op {
    public Div() {
        super('/');
    }

    public int calc(int a, int b) {
        return a / b;
    }
}

class Mod extends Op {
    public Mod() {
        super('%');
    }

    public int calc(int a, int b) {
        return a % b;
    }
}

class Power extends Op {
    public Power() {
        super('^');
    }

    public int calc(int a, int b) {
        int t = a;
        while (--b != 0) {
            t *= a;
        }
        return t;
    }
}

public class OpTest {
    // (5 ? 3) ? 2 = 4

    static public void test(Op a, Op b) {
        if (b.calc(a.calc(5, 3), 2) == 4) {
            System.out.printf("(5 %c 3) %c 2 = 4\n", a.ch, b.ch);
        }
    }

    static public void main(String [] args) {
        // test1();

        Op [] op = {
            new Add(),
            new Sub(),
            new Mul(),
            new Div(),
            new Mod(),
            new Power()
        };

        for (Op o : op) {
            for (Op p : op) {
                test(p, o);
            }
        }
    }

    static public void test1() {
        char op[] = {'+', '-', '*', '/', '%', '^'};

        for (char i : op) {
            for (char j : op) {
                if (calc(calc(5, 3, j), 2, i) == 4) {
                    System.out.printf("(5 %c 3) %c 2 = 4\n", j, i);
                }
            }
        }
    }

    static public int calc(int a, int b, char ch) {
        int ret = 0;

        switch (ch) {
            case '+':
                ret = a + b;
                break;
            case '-':
                ret = a - b;
                break;
            case '*':
                ret = a * b;
                break;
            case '/':
                ret = a / b;
                break;
            case '%':
                ret = a % b;
                break;
            case '^':
                ret = a;
                while (--b != 0) {
                    ret *= a;
                }
                break;
            default:
                break;
        }
        return ret;
    }
}
